#
# Top-level Makefile for building the Genode release
#

MAKEOVERRIDES =

usage:
	@echo "--- available targets ---"
	@echo "build            - build everything"
	@echo "build_3rd        - build third-party software"
	@echo "build_linux_x86  - build Genode for the Linux platform"
	@echo "build_fiasco_x86 - build Genode for the Fiasco/x86 platform"
	@echo
	@echo "You need to set BUILD_DIR to the compound directory, which will"
	@echo "contain all build directories. This directory does not need to"
	@echo "exist prior calling this Makefile."
	@echo

ifeq ($(BUILD_DIR),)
build build_3rd build_linux_x86 build_fiasco_x86:: usage
	@echo "Error: BUILD_DIR not defined"
	@false
endif

GENODE_DIR                 := $(shell pwd)
BUILD_DIR_GENODE_LINUX_X86  = $(BUILD_DIR)/genode.linux_x86
BUILD_DIR_GENODE_FIASCO_X86 = $(BUILD_DIR)/genode.fiasco_x86
BUILD_DIR_3RD               = $(BUILD_DIR)/3rd

$(BUILD_DIR):
	@mkdir $@

build_linux_x86::
	@$(GENODE_DIR)/tool/builddir/create_builddir linux_x86 \
	                                            BUILD_DIR=$(BUILD_DIR_GENODE_LINUX_X86) \
	                                            GENODE_DIR=$(GENODE_DIR)
	@make -C $(BUILD_DIR_GENODE_LINUX_X86)

build_fiasco_x86::
	@$(GENODE_DIR)/tool/builddir/create_builddir fiasco_x86 \
	                                            BUILD_DIR=$(BUILD_DIR_GENODE_FIASCO_X86) \
	                                            GENODE_DIR=$(GENODE_DIR) \
	                                            L4_DIR=$(BUILD_DIR_3RD)/l4env
	@make -C $(BUILD_DIR_GENODE_FIASCO_X86)

build_3rd::
	@mkdir -p $(BUILD_DIR_3RD)
	@BUILD_DIR=$(BUILD_DIR) make -C 3rd build

build:: build_3rd build_linux_x86 build_fiasco_x86

cleanall:
	@rm -rf $(BUILD_DIR)
